package plus.easydo.server.file.store.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import plus.easydo.core.result.R;
import plus.easydo.core.vaild.Insert;
import plus.easydo.core.vaild.Update;
import plus.easydo.server.file.store.dto.FileManagementDto;
import plus.easydo.server.file.store.qo.FileManagementQo;
import plus.easydo.server.file.store.service.FileManagementService;
import plus.easydo.server.file.store.vo.FileManageVo;
import plus.easydo.starter.mybatis.plus.base.MPBaseController;
import plus.easydo.starter.mybatis.plus.result.MPDataResult;

import javax.annotation.Resource;
import java.util.List;

/**
 * 文件管理Controller
 * 
 * @author gebilaoyu
 * @date 2021-11-12 13:47:40
 */
@Api(tags = "文件管理")
@RestController
@RequestMapping("/fileManagement")
public class FileManagementController extends MPBaseController
{
    @Resource
    private FileManagementService fileManagementService;

    /**
     * 分页条件查询文件列表
     */
    @ApiOperation(value = "分页条件查询文件列表")
//    @CustomizePreAuthorize(hasPermission = {"server:fileManagement:list"})
    @PostMapping("/page")
    public MPDataResult page(@RequestBody FileManagementQo qo) {
        IPage<FileManageVo> page = fileManagementService.page(qo);
        return ok(page);
    }

    /**
     * 获取所有文件列表
     */
    @ApiOperation(value = "获取所有文件列表")
//    @CustomizePreAuthorize(hasPermission = {"server:fileManagement:list"})
    @GetMapping("/list")
    public R<List<FileManageVo>> list(@RequestBody FileManagementQo qo) {
        return ok(fileManagementService.list(qo));
    }


    /**
     * 获取文件详细信息
     */
    @ApiOperation(value = "获取文件详细信息")
//    @CustomizePreAuthorize(hasPermission = {"server:fileManagement:query"})
    @GetMapping(value = "/{id}")
    public R<Object> getInfo(@PathVariable("id") Long id) {
        return ok(fileManagementService.selectById(id));
    }

    /**
     * 新增文件
     */
    @ApiOperation(value = "新增文件")
//    @CustomizePreAuthorize(hasPermission = {"server:fileManagement:add"})
    @PostMapping
    public R<Object> add(@RequestBody @Validated(Insert.class) FileManagementDto dto) {
        return opResult(fileManagementService.insert(dto));
    }

    /**
     * 修改文件
     */
    @ApiOperation(value = "修改文件")
//    @CustomizePreAuthorize(hasPermission = {"server:fileManagement:edit"})
    @PutMapping
    public R<Object> edit(@RequestBody @Validated(Update.class) FileManagementDto dto) {
        return opResult(fileManagementService.update(dto));
    }

    /**
     * 删除文件
     */
    @ApiOperation(value = "删除文件")
//    @CustomizePreAuthorize(hasPermission = {"server:fileManagement:remove"})
	@DeleteMapping("/{ids}")
    public R<Object> remove(@PathVariable Long[] ids) {
        return opResult(fileManagementService.deleteByIds(ids));
    }
}
